package com.lhn.netty.netty_demo.http;

import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.Channel;
import io.netty.channel.ChannelFuture;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioServerSocketChannel;

/**
 * http 服务端
 *
 * @author lhn
 * @date 2025/06/01 17:38
 * @since 1.0.0
 **/
public class TestServer {

    public static void main(String[] args) {
        EventLoopGroup bossGroup = new NioEventLoopGroup(1);
        EventLoopGroup workerGroup = new NioEventLoopGroup();

        try {
            ServerBootstrap serverBootstrap = new ServerBootstrap();
            serverBootstrap.group(bossGroup, workerGroup)
                    .channel(NioServerSocketChannel.class) // 该方法用来设置一个服务器端的通道实现
                    //.handler(null) //  bossGroup 的 EventLoopGroup 不能设置处理器
                    .childHandler(new TestServerInitializer()) //  给 workerGroup 的 EventLoopGroup 设置处理器
                    //.childOption( SO_KEEPALIVE, true)
            ;
            ChannelFuture channelFuture = serverBootstrap.bind(16668).sync();

            Channel channel = channelFuture.channel() ;

            // 关闭 通道进行监听
            channelFuture.channel().closeFuture().sync();
        }  catch (Exception e) {
            e.printStackTrace();
        }
    }

}